package com.aqie.arithmetic.object;

import com.aqie.libs.Counter;
import com.aqie.libs.StdOut;
import com.aqie.libs.StdRandom;

/**
 * java Flips 1000
 * 掷硬币
 */
public class Flips {
    public static void main(String[] args) {
        int T = Integer.parseInt(args[0]);
        Counter heads = new Counter("heads");
        Counter tails = new Counter("tails");
        for (int t = 0; t < T; t++){
            if (StdRandom.bernoulli(0.5))
                heads.increment();
            else tails.increment();
        }
        StdOut.println(heads);
        StdOut.println(tails);
        int d = heads.tally() - tails.tally();
        StdOut.println("delta: " + Math.abs(d));

        StdOut.println(max(heads, tails) + " win");
    }

    public static Counter max(Counter x, Counter y){
        if (x.tally() > y.tally()) return x;
        else return y;
    }
}
